/*
* SuctionSumController.java
* Created on  2015/7/21 10:30
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/7/21       longshihui    初始版本
*
*/

package com.infitecs.eyas.oncefan;

import com.infitecs.eyas.expression.service.ExpressionService;
import com.infitecs.eyas.oncefan.model.OnceFanSummary;
import com.infitecs.eyas.oncefan.service.OnceFanSummaryService;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/OnceFan/summary")
public class OnceSumController {

    @Autowired
    private SessionService sessionService;

    @Autowired
    private OnceFanSummaryService onceFanSummaryService;

    @Autowired
    private ExpressionService expressionService;

    @RequestMapping("")
    public String getPage(){
        try {
            sessionService.getCaseId();
            OnceFanSummary onceFanSummary = onceFanSummaryService.getOnceFanSummary();
            if (onceFanSummary == null) {
                onceFanSummaryService.insertNewSummary();
            }
        } catch (Exception e) {
            return "oncefan/summary";
        }
        sessionService.setEnvironment('C');
        return "oncefan/summary";
    }

    @RequestMapping(value = "/getCalculateInit", method = RequestMethod.POST)
    @ResponseBody
    public void getCalculateInit() {
        sessionService.putOnceFanSummaryInit(sessionService.getCaseId());
    }

    @RequestMapping(value = "/getAutoCalculate", method = RequestMethod.POST)
    @ResponseBody
    public OnceFanSummary getAutoCalculate() {
        OnceFanSummary onceFanSummary = new OnceFanSummary();
        Map<String,Double> map = sessionService.getParamMap();
        onceFanSummary.setE21(map.get("CE21"));
        onceFanSummary.setE20(map.get("CE20"));
        onceFanSummary.setE52(map.get("CE52"));
        onceFanSummary.setE63(map.get("CE63"));
        onceFanSummary.setE43(expressionService.calculate(new Param("CE43")));
        onceFanSummary.setE47(expressionService.calculate(new Param("CE47")));
        onceFanSummary.setE48(expressionService.calculate(new Param("CE48")));
        onceFanSummary.setE50(expressionService.calculate(new Param("CE50")));
        onceFanSummary.setE51(expressionService.calculate(new Param("CE51")));
        onceFanSummary.setE53(expressionService.calculate(new Param("CE53")));
        onceFanSummary.setE58(expressionService.calculate(new Param("CE58")));
        onceFanSummary.setE59(expressionService.calculate(new Param("CE59")));
        onceFanSummary.setE61(expressionService.calculate(new Param("CE61")));
        onceFanSummary.setE65(expressionService.calculate(new Param("CE65")));
        onceFanSummary.setE45(map.get("CE45"));
        onceFanSummary.setE46(map.get("CE46"));
        onceFanSummary.setE49(map.get("CE49"));
        onceFanSummary.setE44(map.get("CE44"));
        onceFanSummary.setE54(map.get("CE54"));
        onceFanSummary.setE55(map.get("CE55"));
        onceFanSummary.setE56(map.get("CE56"));
        onceFanSummary.setE57(map.get("CE57"));
        onceFanSummary.setE60(map.get("CE60"));
        onceFanSummary.setE62(map.get("CE62"));
        onceFanSummary.setE64(map.get("CE64"));
        return onceFanSummary;
    }
}
